module SyllableCounter
  class Count
    def initialize(rules, exceptions)
      @rules = rules 
      @exceptions = exceptions
    end

    def call(string)
      get_syllable_count(string)
    end

    private

    attr_reader :rules, :exceptions

    def get_syllable_count(string)
      count = 0
      string.split.each do |word|
        if is_exception?(word)
          count += exceptions[word]
        else
          count += count_vowels(rules.call(word))
        end
      end
      count
    end

    def count_vowels(string)
      string.scan(/[aeiouy%]/).count
    end

    def is_exception?(word)
      exceptions.keys.include?(word)
    end
  end
end
